package com.truthbean.jeetb.tests;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.datasources.DatasourcesFraction;
import org.wildfly.swarm.undertow.WARArchive;

/**
 * Created by TruthBean on 2016-10-13 11:20.
 */
public class Main {

    public static void main(String[] args) throws Exception {

        Swarm swarm = new Swarm()
           .fraction(new DatasourcesFraction()
                .jdbcDriver("h2", (d) -> {
                    d.driverClassName("org.h2.Driver");
                    d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
                    d.driverModuleName("com.h2database.h2");
                })
                .dataSource("ExampleDS", (ds) -> {
                    ds.driverName("h2");
                    ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
                    ds.userName("sa");
                    ds.password("sa");
                }));

        WARArchive deployment = ShrinkWrap.create(WARArchive.class);
        deployment.addPackage("com.truthbean.jeetb.model.sys.repository");
        deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", Main.class.getClassLoader()), "classes/META-INF/persistence.xml");
        deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/sql/data.sql", Main.class.getClassLoader()), "classes/META-INF/sql/data.sql");

        swarm.deploy(deployment);
        
        swarm.start();
    }

}
